package com.lion.common.modules.uaa.web.models.params;

import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author Chris Chan
 * Create On 2025/8/8 下午9:44
 * Use for:
 * Explain:
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Schema(description = "完善账号数据参数")
public class CompleteAccountParam implements Serializable {
    private static final long serialVersionUID = 1L;
    @NotNull(message = "账号编码不能为空")
    @Schema(description = "账号编码", example = "123456")
    private Long accountCode;

    @NotBlank(message = "用户名不能为空")
    @Size(min = 6, max = 20, message = "用户名长度必须在6-20之间")
    @Schema(description = "用户名", example = "chris")
    private String username;

    @NotBlank(message = "手机号不能为空")
    @Pattern(regexp = "^1[3-9]\\d{9}$", message = "手机号格式错误")
    @Schema(description = "手机号", example = "13811111111")
    private String cellphone;

    @NotBlank(message = "邮箱不能为空")
    @Email(message = "邮箱格式错误")
    @Schema(description = "邮箱", example = "def@two.com")
    private String email;

    @NotBlank(message = "验证码不能为空")
    @Schema(description = "验证码", example = "9527")
    private String verifyCode;

    @NotBlank(message = "密码不能为空")
    @Size(min = 6, max = 20, message = "密码长度必须在6-20之间")
    @Schema(description = "密码", example = "123456")
    private String password;

    @NotBlank(message = "确认密码不能为空")
    @Size(min = 6, max = 20, message = "确认密码长度必须在6-20之间")
    @Schema(description = "确认密码", example = "123456")
    private String confirmWord;

    public static CompleteAccountParam create(Long accountCode, String username, String cellphone, String email, String verifyCode, String password, String confirmWord) {
        return new CompleteAccountParam(accountCode, username, cellphone, email, verifyCode, password, confirmWord);
    }

    public static CompleteAccountParam of(Long accountCode, String username, String cellphone, String email, String verifyCode, String password, String confirmWord) {
        return new CompleteAccountParam(accountCode, username, cellphone, email, verifyCode, password, confirmWord);
    }

    @Hidden
    @AssertTrue(message = "两次输入的密码不一致")
    public  boolean isPasswordMatch() {
        return password.equals(confirmWord);
    }
}
